import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {
    private Socket socket = null;
    public TcpClient(String serverIp,int serverPort) throws IOException {
        socket = new Socket(serverIp,serverPort);
    }
    public void start(){
        try( InputStream inputStream = socket.getInputStream();
             OutputStream outputStream = socket.getOutputStream()){
            PrintWriter writer = new PrintWriter(outputStream);
            Scanner scannerNet = new Scanner(inputStream);
            while(true) {
                Scanner scanner = new Scanner(System.in);
                System.out.println("->");
                String request = scanner.next();
                writer.println(request);
                writer.flush();
                if(!scannerNet.hasNext()){
                    break;
                }
                String response = scannerNet.next();
                System.out.println(response);
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        TcpClient tcpClient = new TcpClient("127.0.0.1",9091);
        tcpClient.start();
    }
}

